package com.hbnu.system.controller;

import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.entity.ProjectSourse;
import com.hbnu.system.service.ProjectSourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ProjectSourse")
@Api(tags = "纵向-项目来源模块")
public class ProjectSourseController {
    @Autowired
    private ProjectSourseService projectSourseService;

    @ApiOperation("项目来源添加")
    @PostMapping("/addProjectSourse")
    public Rest<Boolean> addProjectSourse(@RequestBody ProjectSourse projectSourse){
        boolean add = projectSourseService.addProjectSourse(projectSourse);
        return add ? Rest.success():Rest.failed();
    }

    @ApiOperation("获取项目来源列表")
    @GetMapping("/getProjectSourse")
    public Rest<List<ProjectSourse>> getProjectSourse(){
        List<ProjectSourse> projectcateList = projectSourseService.getProjectSourseList();
        return Rest.success(projectcateList);
    }

    @ApiOperation("项目来源-修改")
    @PostMapping("/updateProjectSourse")
    public Rest<Boolean> updateProjectSourse(@RequestBody ProjectSourse projectSourse){
        boolean update = projectSourseService.updateProjectSourse(projectSourse);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("项目来源-删除")
    @GetMapping("/deleteProjectSourse")
    public Rest<Boolean> deleteProjectSourse(String ID){
        boolean delete = projectSourseService.deleteProjectSourse(ID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("项目来源-根据名字查询")
    @GetMapping("/getProjectSourseByName")
    public Rest<List<ProjectSourse>> getProjectSourseByName(String projectSourseName){
        List<ProjectSourse> projectSourseList = projectSourseService.getByProjectSourseName(projectSourseName);
        return Rest.success(projectSourseList);
    }
}
